package com.liyiruo.testMain;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author liyiruo
 * @Description
 * @Date 2023/4/20 下午8:37
 */
public class MybatisTest {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        //静态工厂方式
        InputStream inputStream = Resources.getResourceAsStream(resource);
        //无参构造实例化
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        //获取sqlsession
        SqlSession bean0 = sqlSessionFactory.openSession();
        System.out.println(bean0);

        ApplicationContext context=new ClassPathXmlApplicationContext("mybatis.xml");
        SqlSession bean = context.getBean("sqlSession", SqlSession.class);
        System.out.println(bean);


    }
}
